<template>
  <vxe-modal
    title="办理任务"
    v-model="dialogVisible"
    v-if="dialogVisible"
    :loading="loading"
    width="70%" height="87vh" showFooter esc-closable show-zoom resize>

    <div style="height: 52vh; overflow-y: auto;">
      <el-card class="box-card" shadow="never" :body-style="{ padding: '10px',backgroundColor: '#bfcdda' }">
        <!-- 基本信息 -->
        <el-card class="box-card" shadow="hover">
          <div slot="header" class="clearfix">
            <span style="font-size: 16px; color: #1890ff;">基本信息</span>
          </div>
          <el-descriptions class="margin-top" :column="2" size="medium" border
                           :contentStyle="content_style" :labelStyle="label_style">
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  课题名称：
                </div>
              </template>
              {{ zxTbData.ktName }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  课题编号：
                </div>
              </template>
              {{ zxTbData.ktBh }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  委托单位：
                </div>
              </template>
              {{ zxTbData.wtDw }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  项目负责人：
                </div>
              </template>
              {{ zxTbData.xmFzName }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  上报所属时间：
                </div>
              </template>
              {{ zxTbData.sbSsQTime }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  至：
                </div>
              </template>
              {{ zxTbData.sbSsZTime }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  上报人员：
                </div>
              </template>
              {{ zxTbData.sbRy }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  上报年度：
                </div>
              </template>
              {{ zxTbData.sbNd }}
            </el-descriptions-item>
          </el-descriptions>

          <el-descriptions class="margin-top" :column="1" size="medium" border direction="vertical">
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  执行情况：
                </div>
              </template>
              {{ zxTbData.zxQk }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  经费使用情况：
                </div>
              </template>
              {{ zxTbData.jfSyQk }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  存在的问题:
                </div>
              </template>
              {{ zxTbData.czDWt }}
            </el-descriptions-item>
          </el-descriptions>
        </el-card>
        <br>
        <!-- 一、项目概述 -->
        <el-card class="box-card" shadow="hover" style="min-height: 25vh">
          <div slot="header" class="clearfix">
            <span style="font-size: 16px; color: #1890ff;">一、项目概述</span>
          </div>
          <span style="font-size: 16px; color: #000000; font-weight: 600">1、课题背景:</span>
          <div class="ql-container ql-snow" style="border: 1px solid #ffffff;">
            <div class="ql-editor" style="font-size: 16px">
              <div v-html="zxTbData.ktBj"></div>
            </div>
          </div>

          <span style="font-size: 16px; color: #000000; font-weight: 600">2、研究内容:</span>
          <div class="ql-container ql-snow" style="border: 1px solid #ffffff;">
            <div class="ql-editor" style="font-size: 16px">
              <div v-html="zxTbData.yjNr"></div>
            </div>
          </div>
        </el-card>
        <br>
        <!-- 二、技术难点与创新点 -->
        <el-card class="box-card" shadow="hover" style="min-height: 25vh">
          <div slot="header" class="clearfix">
            <span style="font-size: 16px; color: #1890ff;">二、技术难点与创新点</span>
          </div>
          <span style="font-size: 16px; color: #000000; font-weight: 600">1、技术难点:</span>
          <div class="ql-container ql-snow" style="border: 1px solid #ffffff;">
            <div class="ql-editor" style="font-size: 16px">
              <div v-html="zxTbData.jsNd"></div>
            </div>
          </div>

          <span style="font-size: 16px; color: #000000; font-weight: 600">2、技术创新点:</span>
          <div class="ql-container ql-snow" style="border: 1px solid #ffffff;">
            <div class="ql-editor" style="font-size: 16px">
              <div v-html="zxTbData.jsCxd"></div>
            </div>
          </div>
        </el-card>
        <br>
        <!-- 三、主要技术指标及经济指标 -->
        <el-card class="box-card" shadow="hover" style="min-height: 25vh">
          <div slot="header" class="clearfix">
            <span style="font-size: 16px; color: #1890ff;">三、主要技术指标及经济指标</span>
          </div>
          <span style="font-size: 16px; color: #000000; font-weight: 600">1、技术指标:</span>
          <div class="ql-container ql-snow" style="border: 1px solid #ffffff;">
            <div class="ql-editor" style="font-size: 16px">
              <div v-html="zxTbData.jsZb"></div>
            </div>
          </div>

          <span style="font-size: 16px; color: #000000; font-weight: 600">2、经济指标:</span>
          <div class="ql-container ql-snow" style="border: 1px solid #ffffff;">
            <div class="ql-editor" style="font-size: 16px">
              <div v-html="zxTbData.jjZb"></div>
            </div>
          </div>
        </el-card>
        <br>
        <!-- 附件资料 -->
        <el-card class="box-card" shadow="hover" style="min-height: 25vh">
          <div slot="header" class="clearfix">
            <span style="font-size: 16px; color: #1890ff;">附件资料</span>
          </div>
          <el-table height="30vh" :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                    :data="zxTbFjList">
            <el-table-column label="序号" align="center" type="index" width="50"/>
            <el-table-column label="文件名称" align="center" :formatter="getFileNames" prop="fileName"/>
            <el-table-column label="文件大小" align="center" prop="fileSize" width="150"/>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDownload(scope.row)"
                >下载
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
        <br>

      </el-card>
    </div>
    <el-divider></el-divider>

    <el-card shadow="never">
      <el-form label-width="100px">
        <el-form-item label="审核状态：">
          <el-radio label="1" v-model="submitType">同意</el-radio>
          <el-radio label="2" v-model="submitType">驳回</el-radio>
          <el-select remote v-if="submitType==='2'" v-model="denyTo" placeholder="驳回到：" @visible-change="selectBefore">
            <el-option
              v-for="item in beforeData"
              :key="item.dkey"
              :label="item.taskName"
              :value="item.dkey">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="审核意见：">
          <el-input type="textarea" v-model="comment"></el-input>
        </el-form-item>
      </el-form>
    </el-card>

    <div slot="footer" class="dialog-footer dialog-footer-center">
      <el-button type="primary" @click="onSubmit()">提交</el-button>
      <el-button @click="dialogVisible=false">关闭</el-button>
    </div>
  </vxe-modal>
</template>
<script>

import {fallBackTaskByTaskDefinitionKey, passTask, selectBefore, selectHistory} from "@/api/activiti/task"
import {getZxtb} from "@/api/xmgl/zxgl/zxtb";

export default {
  name: "ZxTbSq", //执行填报审批界面
  dicts: ['sys_user_sex', 'rcpt_zc', 'rcpt_sxly', 'rcpt_ryfl', 'rcpt_sf'],
  data() {
    return {
      loading: false,
      zxTbData: [], //执行填报基本信息列表
      zxTbFjList: [], //执行填报附件信息表
      zxtbId: null, //执行填报主键ID
      beforeData: [],
      beforeDataLoading: false,
      denyTo: null,
      dialogVisible: false,
      rowData: null,
      submitType: "1",//默认同意
      comment: null,//审批意见
      businessData: null,//业务数据
      historyList: [],//历史信息
      content_style: {
        // 解决不对齐的问题
        'width': "400px",
        // 排列第二行
        'word-break': 'break-all',
        // 'background-color': '#f3f7ff'
      },
      label_style: {
        // 解决不对齐的问题
        'width': "250px",
        // 排列第二行
        'word-break': 'break-all',
      },
    };
  },
  created() {
  },
  methods: {
    // 文件下载处理
    handleDownload(row) {
      const resource = row.fileName;
      // 默认方法
      this.$download.resource(resource);
    },
    getFileNames(row) {
      // 从路径中提取文件名
      return row.fileName.split('/').pop(); // 返回文件名部分
    },
    handleOpen(row) {
      this.rowData = row
      this.loading = true;
      this.zxtbId = row.businessKey
      this.dialogVisible = true
      this.getZxTbData()
      setTimeout(() => {
        this.loading = false
      }, 1000)
    },
    //获取详情数据
    getZxTbData() {
      const zxtbId = this.zxtbId
      getZxtb(zxtbId).then(res => {
        this.zxTbData = res.data
        this.zxTbFjList = res.data.zxglZxtbFjList
      })
    },
    //获取之前的节点信息
    selectBefore(visible) {
      //console.log(this.rowData.taskId, "======selectBefore")
      if (visible) {
        this.beforeDataLoading = true;
        this.denyTo = null;
        this.beforeData = [];
        selectBefore({
          taskId: this.rowData.taskId,
          comment: this.comment,
          businessKey: this.rowData.businessKey,
          businessType: this.rowData.businessType,
          processInstanceId: this.rowData.processInstanceId
        }).then(res => {
          this.beforeData = res.data;
          this.$modal.closeLoading();
          this.beforeDataLoading = false;
          this.$options = res.data
        })
      }

    },
    clickTab(tab, event) {
      if (tab.name === 'history') {
        this.getSelectHistory()
      }
    },
    //获取历史记录
    getSelectHistory() {
      selectHistory({processInstanceId: this.rowData.processInstanceId}).then(res => {
        this.historyList = res.data
      })
    },
    //提交
    onSubmit() {
      if (!this.submitType) {
        this.$message.warning("请选择提交类型")
        return
      }
      if (!this.comment) {
        this.$message.warning("请输入审批意见")
        return
      }
      if (this.submitType == 1) {
        console.log(this.rowData, '1111111111111111111111111111111')
        //审核通过
        passTask({
          taskId: this.rowData.taskId,
          comment: this.comment,
          params: {
            // day: this.businessData.qingJiaDay
          },
          businessKey: this.rowData.businessKey,
          businessType: this.rowData.businessType,
          processInstanceId: this.rowData.processInstanceId
        }).then(res => {
          this.dialogVisible = false
          this.$emit('ok')
        })
      }
      //任务驳回
      if (this.submitType == 2) {
        console.log("nnnnnnnnn" + this.denyTo);
        //审核不通过
        fallBackTaskByTaskDefinitionKey({
          comment: this.comment,
          businessKey: this.rowData.businessKey,
          businessType: this.rowData.businessType,
          processInstanceId: this.rowData.processInstanceId,
          taskId: this.rowData.taskId,
          taskDefinitionKey: this.denyTo
        }).then(res => {
          console.log(res, "[[[[")
          this.dialogVisible = false
          this.denyTo = null;
          this.beforeData = [];
          this.$emit('ok')
        })
      }
    },

  }
};
</script>

